//
//  CZStautsCell.swift
//  WeiBo
//
//  Created by apple on 16/6/27.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SnapKit
let StautsMargin: CGFloat = 10

class CZStautsCell: UITableViewCell {
    // 纪录底部toolbar顶部约束
    var toolBarTopConstraint:Constraint?
    
    // 供外界给cell设置数据
    var status: CZStatus? {
        didSet{
            // 给原装微博赋值
            statusOriginalView.status = status
            
            // 先卸载底部 原有约束
            toolBarTopConstraint?.uninstall()
            // 没有转发微博
            if status?.retweeted_status == nil {
                
                statusRetweetView.hidden = true
                //  重新设置约束
                statusToolbar.snp_makeConstraints(closure: { (make) -> Void in
                    toolBarTopConstraint = make.top.equalTo(statusOriginalView.snp_bottom).constraint
                })
                
            }else {
                // 有转发微博
                // 先赋值
                statusRetweetView.status = status
                statusRetweetView.hidden = false
                
                statusToolbar.snp_makeConstraints(closure: { (make) -> Void in
                    toolBarTopConstraint = make.top.equalTo(statusRetweetView.snp_bottom).constraint
                })
            }
            // 给toolbar赋值
            statusToolbar.status = status
            
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //  设置视图
    private func setupUI(){
        self.backgroundColor = RBG(237, green: 237, blue: 237)
        //  添加控件
        contentView.addSubview(statusOriginalView)
        contentView.addSubview(statusRetweetView)
        contentView.addSubview(statusToolbar)
        //  添加约束
        statusOriginalView.snp_makeConstraints { (make) -> Void in
            make.leading.top.trailing.equalTo(contentView)
            
        }
        statusRetweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(statusOriginalView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
        
        }
        statusToolbar.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(contentView)
            // 纪录约束
            toolBarTopConstraint = make.top.equalTo(statusRetweetView.snp_bottom).constraint
            make.height.equalTo(35)
        }
        //cell
        contentView.snp_makeConstraints { (make) -> Void in
            make.top.leading.trailing.equalTo(self)
            make.bottom.equalTo(statusToolbar)
        }
    }
    
    // 加载控件
    // 原创微博
    private lazy var statusOriginalView: CZStatusOriginalView = CZStatusOriginalView()
    // 转发微博
    private lazy var statusRetweetView:CZStatusRetweetView = CZStatusRetweetView()
    // 底部toolbar（转发评论赞）
    private lazy var statusToolbar:CZStatusToolbar = CZStatusToolbar()
    
}
extension CZStautsCell {
    func demo(){




        
    }
}
